package Outil;

/***********************************************************************
 * Module: Buffer.java Author: 12008505 Purpose: Defines the Class Buffer
 ***********************************************************************/

/**
 * Originator
 */
public class Buffer {

	private StringBuffer Ztravail;

	public Buffer() {
		Ztravail = new StringBuffer();
	}

	public void ajouterZoneDeTravailChar(char c, int debut) {

		Ztravail = Ztravail.insert(debut, c);

	}

	public void setZtravail(StringBuffer ztravail) {
		Ztravail = ztravail;
	}

	public void ajouterZoneDeTravailString(String s, int debut) {

		Ztravail.insert(debut, s);

	}

	public StringBuffer getZoneDeTravail() {
		return Ztravail;
	}

	public void supprimer(int debut, int fin) {
		Ztravail.delete(debut, fin + 1);
	}

	public String getSelectedText(int debut, int fin) {
		return Ztravail.substring(debut, fin);
	}

	public String getText() {
		return Ztravail.substring(0);
	}

	public BufferMemento creerMemento() {
		return new BufferMemento(Ztravail.substring(0));
	}

	public void mettreAjourMemento(BufferMemento backup) {

		Ztravail.replace(0, Ztravail.length(), backup.getState());
	}

	public void sauveLigne() {
		Ztravail.append(System.getProperty("line.separator"));
	}

}